package com.somsoft.handjc.activity;

import java.util.ArrayList;
import java.util.HashMap;

import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.SimpleAdapter;

import com.somsoft.handjc.util.BaseActivity;

public abstract class BaseGridViewActivity extends BaseActivity implements OnItemClickListener{
	
	protected void createGridView(GridView gridview,Integer[] pics,String[] titles){
		// 生成动态数组，并且转入数据
				ArrayList<HashMap<String, Object>> lstImageItem = new ArrayList<HashMap<String, Object>>();
				for (int i = 0; i < pics.length; i++) {
					HashMap<String, Object> map = new HashMap<String, Object>();
					map.put("ItemImage", pics[i]);// 添加图像资源的ID
					map.put("ItemText", titles[i]);// 按序号做ItemText
					lstImageItem.add(map);
				}
				// 生成适配器的ImageItem <====> 动态数组的元素，两者一一对应
				SimpleAdapter saImageItems = new SimpleAdapter(this, // 没什么解释
						lstImageItem,// 数据来源
						R.layout.gridviewitem,// night_item的XML实现
						// 动态数组与ImageItem对应的子项
						new String[] { "ItemImage", "ItemText" },
						// ImageItem的XML文件里面的一个ImageView,两个TextView ID
						new int[] { R.id.ItemImage, R.id.ItemText });
				// 添加并且显示
				gridview.setAdapter(saImageItems);
				// 添加消息处理
				gridview.setOnItemClickListener(this);
	}

}